﻿Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization

Imports SharpDX.Direct2D1
Imports TerrariaVB.Core.Helper

<Serializable()>
Public Class NpcXmlInfo

#Region ".Cctor"
    Public Sub New()
        Type = 0
        Width = 0
        Height = 0
        Name = "NULL"
        MaxHealth = 100
        Aggresive = False
        UsesMelee = False
        UsesMagic = False
        UsesRange = False
        BaseDamage = 0
        BaseDefence = 0
        BaseAttackRange = 1
        MaxAnimations = 2
        HasPhysics = True
    End Sub
#End Region

#Region "Constants"
    Public Const C_NPC_DIR As String = "Npcs\"
    Public Const C_XML_EXT As String = ".xml"
    Public Const C_IMG_EXT As String = ".png"
    Public Const C_IMG_DIR As String = "Img\"
    Public Const C_BASE_NAME As String = "npc_"
#End Region

#Region "Properties"
    Public Property Type() As Int32
    Public Property Width() As Int32
    Public Property Height() As Int32
    Public Property Name() As String
    Public Property MaxHealth() As Int32
    Public Property Aggresive() As Boolean
    Public Property UsesMelee() As Boolean
    Public Property UsesRange() As Boolean
    Public Property UsesMagic() As Boolean
    Public Property BaseDamage() As Int32
    Public Property BaseDefence() As Int32
    Public Property BaseAttackRange() As Int32
    Public Property MaxAnimations() As Int32
    Public Property HasPhysics() As Boolean
#End Region

#Region "Shared"
    Public Shared Function LoadInfo(T As Int32, e As Core.Base.GameCoreEventArgs) As NpcXmlInfo
        Dim svcContent As Zip = e.Core.Services.GetService(GetType(Zip))
        Dim strPathToFile As String = C_NPC_DIR & C_BASE_NAME & T & C_XML_EXT
        Dim fsXmlFile As Stream = svcContent.Extract(strPathToFile)
        Dim returnInfo As New NpcXmlInfo()
        Dim decoder As New XmlSerializer(returnInfo.GetType())
        returnInfo = CType(decoder.Deserialize(fsXmlFile), NpcXmlInfo)
        Return returnInfo
    End Function

    Public Shared Function LoadImage(T As Int32, e As Core.Base.GameCoreEventArgs) As Bitmap
        Dim svcContent As Zip = e.Core.Services.GetService(GetType(Zip))
        Dim strImgPath As String = C_NPC_DIR & C_IMG_DIR & C_BASE_NAME & T & C_IMG_EXT
        Return BitmapHelper.LoadFromStream(e.Core.RenderTarget2D, svcContent.Extract(strImgPath), Color.Fuchsia)
    End Function

    Public Shared Sub CreateDefaults()
        Dim n As New NpcXmlInfo()
        n.Save()
        n = New NpcXmlInfo()
        n.Type = 1
        n.Name = "Gray Slime"
        n.MaxHealth = 14
        n.MaxAnimations = 1
        n.UsesMelee = True
        n.Aggresive = True
        n.BaseDefence = 0
        n.BaseDamage = 6
        n.Height = 26
        n.Width = 32
        n.Save()
        n = New NpcXmlInfo()
        n.Type = 2
        n.Name = "Demon Eye"
        n.HasPhysics = False
        n.MaxHealth = 60
        n.UsesMelee = True
        n.BaseAttackRange = 1
        n.BaseDamage = 16
        n.BaseDefence = 2
        n.MaxAnimations = 1
        n.Aggresive = True
        n.Width = 38
        n.Height = 24
        n.Save()
        n = New NpcXmlInfo()
        n.Type = 3
        n.Name = "Zombie"
        n.MaxHealth = 45
        n.UsesMelee = True
        n.Aggresive = True
        n.BaseAttackRange = 1
        n.MaxAnimations = 2
        n.Width = 34
        n.Height = 48
        n.BaseDefence = 3
        n.BaseDamage = 14
        n.Save()
    End Sub
#End Region

#Region "Methods"
    Public Sub Save()
        Return

        Dim strPathToFile As String = C_NPC_DIR & C_BASE_NAME & Me.Type & C_XML_EXT
        Dim fsXmlFile As FileStream = File.Open(strPathToFile, FileMode.OpenOrCreate, FileAccess.Write)
        Dim encoder As New XmlSerializer(Me.GetType())
        encoder.Serialize(fsXmlFile, Me)
    End Sub
#End Region

#Region "Functions"

#End Region

End Class
